package ${content.controllerContent.classPackage};

import java.util.Date;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.gzqixun.core.annotation.SysLog;
import io.gzqixun.core.utils.PageUtils;
import io.gzqixun.core.utils.Result;
import ${content.serviceContent.classPackage}.${content.serviceContent.className};
import ${content.entityContent.classPackage}.${content.entityContent.className};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
 * ${content.entityContent.description}
 * 
 * @author ${author} 
 *
 */
@RestController
@RequestMapping("/${content.controllerContent.className}")
public class ${content.controllerContent.className} {

	@Reference
	private ${content.serviceContent.className} ${content.serviceContent.className?uncap_first};
	
	
	@SysLog("获取${content.entityContent.description}列表")
	@PostMapping("/list")
	@ApiOperation(value = "获取${content.entityContent.description}列表",notes = "根据params获取${content.entityContent.description}列表",response = ${content.entityContent.className}.class)
	public Result list(@RequestBody Map<String, Object> params){
		PageUtils page = ${content.serviceContent.className?uncap_first}.queryPage(params);
		return Result.success(page);
	}
	
	@SysLog("获取${content.entityContent.description}详情")
	@GetMapping("/info")
	@ApiOperation(value = "获取${content.entityContent.description}详情",notes = "根据id获取${content.entityContent.description}详情",response = ${content.entityContent.className}.class)
	public Result info(String id){
		${content.serviceContent.className} byId = ${content.serviceContent.className?uncap_first}.getById(id);
		return Result.success(byId);
	}
	
	@SysLog("保存${content.entityContent.description}")
	@PostMapping("/save")
	@ApiOperation(value = "保存${content.entityContent.description}",notes = "保存${content.entityContent.description}",response = Boolean.class)
	public Result save(@RequestBody ${content.serviceContent.className} entity){
		if(StringUtils.isBlank(entity.getId())) {
			entity.setCreateBy(getUserId());
			entity.setUpdateBy(getUserId());
			entity.setCreated(new Date());
		}else {
			entity.setUpdateBy(getUserId());
			entity.setUpdated(new Date());
		}
		boolean saveOrUpdate = ${content.serviceContent.className?uncap_first}.saveOrUpdate(entity);
		return Result.success(saveOrUpdate);
	}
	
	
	@SysLog("删除${content.entityContent.description}")
	@PostMapping("/delete")
	@ApiOperation(value = "删除${content.entityContent.description}",notes = "根据id删除${content.entityContent.description}",response = Boolean.class)
	public Result delete(String id){
		boolean r=   ${content.serviceContent.className?uncap_first}.removeById(id);
		return Result.success(r);
	}
	 
}
